import { defineStore } from 'pinia';

interface ICommonState {
  // 页面文档可视高度(随窗口改变大小)
  documentClientHeight: string,
  // 导航条, 布局风格, defalut(默认) / inverse(反向)
  navbarLayoutType: string,
  // 侧边栏, 布局皮肤, light(浅色) / dark(黑色)
  sidebarLayoutSkin: string,
  // 侧边栏, 折叠状态
  sidebarFold: boolean,
  // 侧边栏, 菜单
  menuList: any[],
  menuActiveName: string,
  // 内容, 是否需要刷新
  contentIsNeedRefresh: boolean,
  // 主入口标签页
  mainTabs: any[],
  mainTabsActiveName: string
}

export const usecommonStore = defineStore({
  id: 'app-common',
  state: (): ICommonState => ({
    documentClientHeight: '0',
    navbarLayoutType: 'default',
    sidebarLayoutSkin: 'dark',
    sidebarFold: false,
    menuList: [],
    menuActiveName: '',
    contentIsNeedRefresh: false,
    mainTabs: [],
    mainTabsActiveName: ''
  }),
  getters: {},
  actions: {
    updateDocumentClientHeight(height: string) {
      this.documentClientHeight = height
    },
    updateNavbarLayoutType(type: string) {
      this.navbarLayoutType = type
    },
    updateSidebarLayoutSkin(skin: string) {
      this.sidebarLayoutSkin = skin
    },
    updateSidebarFold(fold: boolean) {
      this.sidebarFold = fold
    },
    updateMenuList(list: any[]) {
      this.menuList = list
    },
    updateMenuActiveName(name: string) {
      this.menuActiveName = name
    },
    updateContentIsNeedRefresh(status: boolean) {
      this.contentIsNeedRefresh = status
    },
    updateMainTabs(tabs: any[]) {
      this.mainTabs = tabs
    },
    updateMainTabsActiveName(name: string) {
      this.mainTabsActiveName = name
    }
  }
})
